package com.ft.turorial.spring.boot.security.oauth2.service;

import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ft.turorial.spring.boot.security.oauth2.domain.OAuth2Client;
import com.ft.turorial.spring.boot.security.oauth2.mapper.OAuth2ClientMapper;

@Service
public class OAuth2ClientServiceImpl implements OAuth2ClientService {

	@Resource
	private OAuth2ClientMapper clientMapper;
	
	@Override
	public OAuth2Client createOauth2Client(OAuth2Client client) {
		client.setClientId(UUID.randomUUID().toString());
        client.setClientSecret(UUID.randomUUID().toString());
        return clientMapper.createOauth2Client(client);
	}

	@Override
	public OAuth2Client updateOauth2Client(OAuth2Client client) {
		return clientMapper.updateOauth2Client(client);
	}

	@Override
	public void deleteOauth2Client(Long clientId) {
		clientMapper.deleteOauth2Client(clientId);
	}

	@Override
	public OAuth2Client findOne(Long clientId) {
		return clientMapper.findOne(clientId);
	}

	@Override
	public List<OAuth2Client> findAll() {
		return clientMapper.findAll();
	}

	@Override
	public OAuth2Client findByClientId(String clientId) {
		return clientMapper.findByOauth2ClientId(clientId);
	}

	@Override
	public OAuth2Client findByClientSecret(String clientSecret) {
		return clientMapper.findByOauth2ClientSecret(clientSecret);
	}

}
